<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="columns => this.columns = columns"
      :isExportExcel2="true"
      :exportFileName="customExportFileName"
    >
    </FilterTable>

    <BaseDialog
      :visible.sync="issearch"
      :title="'服务商查询'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <ownerSeacher  @close="dealercloseHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getInfo } from '@/api/partsmanage/waybill/query/index';
import ownerSeacher from '@/pages/partsmanage/claim/approve/ownerSeacher';
import moment from 'moment';
export default {
  name: "partWaybill",
  mixins: [dictionary],
  components: {ownerSeacher},
  data() {
    return{
        topFilterList: this.createTopFilterList(),
        columns: this.createTableColumns(),
        fetchApi: getInfo,
        issearch: false,
        fetchParams: {xhrAbort: true},    
        customExportFileName:'物流单明细'+moment().format("YYYY-MM-DD")+'.xlsx',
    };
  },
  async created() {
  },
  methods: {
    createTopFilterList() {
      return[
        {
          type: 'INPUT',
          label: '服务商代码',
          fieldName: 'dealerCode',
          placeholder: '请选择',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          }
        },
        {
          type: 'INPUT',
          label: '服务商简称',
          fieldName: 'dealerName',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '备件订单号',
          fieldName: 'xsddhm',
          placeholder: '请输入',
        },
        {
          type: 'RANGE_DATE',
          fieldName: 'startTime|endTime',
          label: '发运日期',
          initialValue: [],
          dateType: 'daterange'
        },
        {
          type: 'INPUT',
          label: '交货单号',
          fieldName: 'bsysdh',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '承运单号',
          fieldName: 'tknum',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '物流单号',
          fieldName: 'zexpress',
          placeholder: '请输入',
        },
        {
          type: 'SELECT',
          label: '交货单来源',
          fieldName: 'zjhdly',
          itemList: this.createDictList('3056'),
          placeholder: '请选择...'
        }
      ]
    },
    createTableColumns () {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          align:"center",
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '服务商代码',
          dataIndex: 'dealerCode',
          sorter: true,
          align:"center"
        },
        {
          title: '服务商简称',
          dataIndex: 'dealerName',
          sorter: true,
          align:"center"
        },
        {
          title: '备件订单号',
          dataIndex: 'xsddhm',
          sorter: true,
          width: 180,
          align:"center"
        },
        {
          title: '承运单号',
          dataIndex: 'tknum',
          sorter: true,
          align:"center"
        },
        {
          title: '交货单号',
          dataIndex: 'bsysdh',
          sorter: true,
          align:"center"
        },
        {
          title: '交货单来源',
          dataIndex: 'zjhdly',
          align:"center",
          dictItems:this.createDictList('3056'),
          sorter: true
        },
        {
          title: '物流单号',
          dataIndex: 'zexpress',
          sorter: true,
          align:"center"
        },
        {
          title: '物流商代码',
          dataIndex: 'waybillCode',
          sorter: true,
          align:"center"
        },
        {
          title: '物流公司',
          dataIndex: 'waybillName',
          sorter: true,
          align:"center"
        },
        {
          title: '联系人',
          dataIndex: 'nameText',
          sorter: true,
          align:"center"
        },
        {
          title: '联系电话',
          dataIndex: 'telNumber',
          sorter: true,
          align:"center"
        },
        {
          title: '发运日期',
          dataIndex: 'shippingTime',
          dateFormat: 'yyyy-MM-dd',//yyyy-MM-dd HH:mm:ss
          sorter: true
        },
        {
          title: '预计交货日期',
          dataIndex: 'dpten',
          dateFormat: 'yyyy-MM-dd',
          sorter: true
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          align:"center"
        },
      ]
    },
    seacherFun(){
      this.issearch = true
    },
    dealercloseHandler(val){
      if(val){
        this.topFilterList.find(x=>x.fieldName=='dealerCode').initialValue=val.dealerCode;
        this.topFilterList.find(x=>x.fieldName=='dealerName').initialValue=val.dealerShortname;
      }
      this.issearch=false;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
  }
}
</script>

<style lang="less" scoped>
</style>
